<template>
    <div class="login-contain">
        <h2>易购商城欢迎您</h2>
        <van-cell-group>
            <van-field v-model="user.username" type="tel" placeholder="请输入手机号:"/>
            <van-field v-model="user.pwd" type="password" placeholder="请输入密码:"/>
        </van-cell-group>

        <van-button @click=Login type="warning" round class="login-button" text="登录"/>

    </div>
</template>

<script>
import {Login} from "@/api/user";
import {Toast} from "vant";

export default {
    name: "LoginView",
    data() {
        return {
            user: {
                username: "",
                pwd: ""
            }
        }
    },
    methods: {
        async Login() {
            let res = await Login(this.user);
            if (res.errno === 0) {
                Toast("登录成功!");
                localStorage.setItem("userInfo", JSON.stringify(res.data.userInfo));
                localStorage.setItem("token", res.data.token);
                setTimeout(() => {
                    this.$router.go(-1);
                }, 1000)
            } else if (res.errno === 602) {

                Toast("密码错误!");
            }
        }
    }
}
</script>

<style scoped lang="less">

.login-contain {
    padding: 30% 5% 40% 5%;
    height: 390px !important;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;


    h2 {
        text-align: center;
        font-size: 25px;
        padding: 0.1rem 0.1rem;
        margin-bottom: 0.3rem;
    }
}

.login-button {
    margin-top: 25px;
    width: 2rem;

}

.van-cell {
    margin-top: 10px;
    width: 3rem;

}

</style>
